import request from '@/utils/request'

// 获取角色列表
export function getRoleList(params?: RoleListParamsType) {
  return request<RoleListType>({
    url: '/setting/role',
    method: 'get',
    params,
  })
}

// 设置角色状态
export function setRoelStatus(id: number, status: 0 | 1) {
  return request<RoleListType>({
    url: `/setting/role/set_status/${id}/${status}`,
    method: 'put',
  })
}

// 获取角色详情
export function getRoleInfo(id: number) {
  return request({
    url: `/setting/role/${id}/edit`,
    method: 'get',
  }).then<RoleInfoType>(res => {
    return res.role
  })
}

// 添加/更新角色
export function submitRole(id: number, data: RoleEditParamsType) {
  return request({
    url: `/setting/role/${id}`,
    method: 'post',
    data,
  })
}

// 删除角色
export function deleteRole(id: number) {
  return request({
    url: `/setting/role/${id}`,
    method: 'delete',
  })
}
